package com.nidu.demo.mail.ability;

import com.alibaba.cola.exception.BizException;
import com.nidu.demo.common.exception.ErrorCodeConstants;
import com.nidu.demo.mail.gateway.MailAccountGateway;
import com.nidu.demo.mail.model.MailAccount;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class MailAccountDomainService {


    private final MailAccountGateway gateway;

    public MailAccount validateMailAccount(Long accountId){
        MailAccount mailAccount = gateway.getById(accountId);
        if (mailAccount == null) {
            throw new BizException(ErrorCodeConstants.MAIL_ACCOUNT_NOT_FOUND.getCode(),
                    ErrorCodeConstants.MAIL_ACCOUNT_NOT_FOUND.getMessage());
        }
        mailAccount.isDeleted();
        return mailAccount;
    }

}